<%@ page contentType="text/html;" 
    import="java.io.*"
    import="java.util.*"
    import="java.text.*"
%><%
        String aFilePath = "";    //要下载的文件路径
        String fileName = request.getParameter("fileName");    //要下载的文件名
//        FileInputStream in = null;  //输入流
        try
        {
             Date now = new Date();
             SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmm");
             response.setContentType("application/msword");
             response.setHeader("Content-disposition", "inline;attachment; filename=" + sdf.format(now) + ".xls" );
             BufferedInputStream bis = null;
             BufferedOutputStream bos = null;
             try 
             {
                bis = new BufferedInputStream(new FileInputStream(aFilePath + fileName));
                bos = new BufferedOutputStream(response.getOutputStream());
                byte[] buff = new byte[2048];
                int bytesRead;

                while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) 
                {
                    bos.write(buff,0,bytesRead);
                }

            } 
            catch(final IOException e) 
            {
                System.out.println ( "出现IOException." + e );
            } 
            finally 
            {
                try
                {
                    if (bis != null)
                        bis.close();
                }
                catch(Exception x)
                {
                    System.out.println("xxxx" + x.toString());
                }
                try
                {
                    if (bos != null)
                        bos.close();
                }
                catch(Exception x)
                {
                    System.out.println("xxxx" + x.toString());
                }
            }
            return;
        }
        catch(Exception x)
        {
            System.out.println("xxxx" + x.toString());
        }
       finally
       {
//             try
//             {
//                 out.close();
//             }
//             catch(Throwable e)
//             {
//                System.out.println("IO close error!" + e.toString());
//             }
             try
             {
                 File f = new File(fileName);
                 System.out.println("删除临时文件:" + fileName);
                 f.delete();
             }
             catch(Exception x)
             {
                 System.out.println("删除 " + fileName + "文件失败" );
             }
      }
%>
